package com.choosefine.it.company.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.choosefine.it.base.BaseController;
import com.choosefine.it.base.dto.PageDTO;
import com.choosefine.it.common.def.ResultCode;
import com.choosefine.it.common.model.CustomRestTemplate;
import com.choosefine.it.common.utils.DateUtils;
import com.choosefine.it.common.utils.StringUtils;
import com.choosefine.it.common.utils.URLHandlerUtils;
import com.choosefine.it.company.model.CompanyFindManagerInfo;
import com.choosefine.it.company.model.CompanyManagerCollection;
import com.choosefine.it.company.model.ManagerContractorInfo;
import com.choosefine.it.company.service.CompanyFindManagerService;
import com.choosefine.it.company.service.CompanyManagerCollectionService;
import com.choosefine.it.manager.model.ManagerFindprojectInfo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 建筑公司-收藏管理
 * 
 * @author chenjian
 * @date 2016-12-3 下午2:18:28
 */
@Deprecated/*yuxin 3.09*/
@RestController
@RequestMapping("/companyManagerCollection")
@Api(value = "建筑公司收藏项目承包人及收藏管理", description = "陈健")
public class CompanyManagerCollectionController extends BaseController {
	/*@Autowired
	private CompanyManagerCollectionService companyManagerCollectionService;
	@Autowired
	private CompanyFindManagerService companyFindManagerService;

	@Value("#{yaml.get('basedata.userinfo.getUserByUserCode')}")
	String userinfoURL = null;

	@Autowired
	CustomRestTemplate restTemplate;

	@Autowired
	ObjectMapper jsonObjectMapper;

	Logger logger = LoggerFactory.getLogger(CompanyManagerCollectionController.class);

	@ApiOperation(value = "建筑公司-我的收藏-根据用户的usercode查看收藏的项目承包人列表", notes = "",response=CompanyManagerCollection.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userCode", value = "项目经理用户的唯一编号", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "pageNum", value = "起始行", required = true, dataType = "Integer", paramType = "query"),
			@ApiImplicitParam(name = "pageSize", value = "一页显示的行数", required = true, dataType = "Integer", paramType = "query") })
	@RequestMapping(value = "/getCompanyColletManagerList/{userCode}", method = RequestMethod.GET,produces = "application/json")
	public String getCompanyColletManagerList(@PathVariable String userCode,
			Integer pageNum, Integer pageSize) {
		String result = null;
		PageDTO page = new PageDTO();
		page.setPageNum(pageNum);
		page.setPageSize(pageSize);
		if (StringUtils.isNotBlank(userCode)) {
			Page<CompanyManagerCollection> list = companyManagerCollectionService.getCompanyManagerCollection(userCode, page);
//			Page<CompanyManagerCollection> mlist = new Page<CompanyManagerCollection>(pageNum, pageSize);
			if (list.size() > 0) {
				for (CompanyManagerCollection companyManagerCollection : list) {
					ManagerFindprojectInfo mc = companyManagerCollectionService.selectManagerFindprojectById(companyManagerCollection.getManagerPublishId());
					if (mc != null) {
						*//*companyManagerCollection.setProjectType(mc.getExpectProjectType());*//*
						companyManagerCollection.setExpectProjectTime(mc.getExpectProjectTime());
						*//*companyManagerCollection.setProjectManager(mc.getProjectManager());*//*
						companyManagerCollection.setUserCode(mc.getUserCode());
						//余鑫。。。。记得修改
//						companyManagerCollection.setAreaCode(mc.getAreaCode());
//						companyManagerCollection.setAreaName(mc.getAreaName());
//						mlist.add(m);
					}
				}
				result=responseSuccess(list);
			}else{
				result= responseFail(ResultCode.FAILED,ResultCode.MSG_DATA_ISEMPTY);
			}
		} else {
			result = responseFail(ResultCode.FAILED, ResultCode.MSG_PARAMS_NULL);
		}
		return result;
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@ApiOperation(value = "建筑公司-我的收藏-根据项目经理求项目的发布publishId查看项目承包人的详情", notes = "该用户的项目经验需要去调用项目经理manager下的项目经验接口",response=ManagerContractorInfo.class)
	@ApiImplicitParam(name = "publishId", value = "发布的ID", required = true, dataType = "Integer", paramType = "path")
	@RequestMapping(value = "/getManagerDetail/{publishId}", method = RequestMethod.GET,produces = "application/json")
	public String getTeamInfoDetail(@PathVariable Integer publishId)
			throws JsonProcessingException {
		String result = null;
		CompanyFindManagerInfo companyFindManagerInfo = companyFindManagerService
				.findCompanyFindManagerInfoById(publishId);
		if (companyFindManagerInfo != null) {
			ManagerContractorInfo managerContractorInfo = new ManagerContractorInfo();
			*//*managerContractorInfo.setAreaCode(companyFindManagerInfo.getAreaCode());
			managerContractorInfo.setAreaName(companyFindManagerInfo.getAreaName());
			managerContractorInfo.setExpectProjectTime(companyFindManagerInfo.getExpectProjectTime());
			managerContractorInfo.setProjectType(companyFindManagerInfo.getProjectType());*//*
			managerContractorInfo.setPublishTime(companyFindManagerInfo.getPublishTime());
			*//*String url = URLHandlerUtils.getUrlBuffer(shixiaobaoURL, userinfoURL).append(companyFindManagerInfo.getUserCode()).toString();*//*
			*//*Map userInfoResultMap = restTemplate.getForObject(url, Map.class,
					new HashMap());*//*
			*//*Map userInfo = (Map) userInfoResultMap.get("data");*//*
			*//*logger.info("序列化结果 :\n"
					+ jsonObjectMapper.writeValueAsString(userInfo));*//*
			*//*String contractor = (String) userInfo.get("realName");
			String headIconUrl = (String) userInfo.get("headIconUrl");
			Integer sex = (Integer) userInfo.get("sex");
			String nativePlace = (String) userInfo.get("nativePlace");
			Integer userAge = (Integer) userInfo.get("userAge");*//*
			*//*managerContractorInfo.setHeadIconUrl(headIconUrl);
			managerContractorInfo.setNativePlace(nativePlace);
			managerContractorInfo.setSex(sex);
			managerContractorInfo.setUserAge(userAge);
			managerContractorInfo.setContractor(contractor);
			managerContractorInfo.setPhone(companyFindManagerInfo.getPhone());*//*
			result = responseSuccess(managerContractorInfo, ResultCode.SUCCESS,
					ResultCode.MSG_SUCCESS);
		} else {
			result = responseFail(ResultCode.FAILED,
					ResultCode.MSG_DATA_ISEMPTY);
		}
		return result;
	}

	@ApiOperation(value = "建筑公司-我的收藏-根据收藏的列表的某条记录的id取消收藏", notes = "")
	@ApiImplicitParam(name = "id", value = "建筑公司收藏的id", required = true, dataType = "Integer", paramType = "path")
	@RequestMapping(value = "/cancleCollectManager/{id}", method = RequestMethod.PUT)
	public String cancleCollectTeam(@PathVariable Integer id) {
		String result = null;
		CompanyManagerCollection companyManagerCollection = null;
		if (id != null&&id.intValue()>0) {
			companyManagerCollection = new CompanyManagerCollection();
			companyManagerCollection.setId(id);
			companyManagerCollection.setIsValid(1);
			companyManagerCollection.setUtime(DateUtils.getNowTime());
			Integer isSuccess = companyManagerCollectionService
					.cancleManagerCollectionById(companyManagerCollection);
			if (isSuccess > 0) {
				result = responseSuccess(isSuccess, ResultCode.SUCCESS,
						ResultCode.MSG_SUCCESS);
			} else {
				result = responseFail(ResultCode.FAILED, ResultCode.MSG_ERROR);
			}
		} else {
			result = responseFail(ResultCode.FAILED, ResultCode.MSG_PARAMS_NULL);
		}
		return result;
	}*/
}
